package com.woniuxy.myshop.mapper;

import com.woniuxy.myshop.entity.Cart;
import com.woniuxy.myshop.vo.CartVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface CartMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(Cart record);

    Cart selectByPrimaryKey(Integer id);

    List<Cart> selectAll();

    int updateByPrimaryKey(Cart record);

    CartVo selectCartByPidAndUserId(@Param("pid") int pid, @Param("uid") Integer uid);

    @Update("update t_cart set buycount = buycount+1 where product_id = #{pid} and user_id = #{userid}")
    void inCreCount(@Param("pid") int pid, @Param("userid") Integer userid);

    @Insert("insert into t_cart (product_id,buycount,user_id) values (#{product.id},#{buycount},#{user.id})")
    void insertCart(CartVo cart);

    List<CartVo> selectMyCart(Integer id);

    List<CartVo> selectSubmitMyCart(@Param("idArr") int[] idArr, @Param("uid") Integer id);

    void deleteSubmitMyCart(@Param("idArr") int[] idArr, @Param("uid") Integer id);
}